﻿using ChestPainCenterSystem.Bll;
using ChestPainCenterSystem.Code.Bll;
using ChestPainCenterSystem.Core;
using ChestPainCenterSystem.Utils;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ChestPainCenterSystem.Areas.ChestPainCenter.Controllers
{
    public class ReportStatusController : BaseController
    {
        //
        // GET: /ChestPainCenter/ReportStatus/

        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 患者总览加载
        /// </summary>
        /// <returns></returns>
        public ContentResult Search()
        {
            string name = WebUtils.GetString("name");
            int status = WebUtils.GetInt("status");
            int pathwayId = WebUtils.GetInt("pathway");
            int pageIndex = WebUtils.GetInt("page", 1);
            int pageSize = WebUtils.GetInt("pageSize", 50);
            string arrivedType = string.Empty;
            OperateResult resultInfo = PatientManager.GetPatientOverview(pageIndex, pageSize, name, status, pathwayId,arrivedType);
            string NoData = "{\"Total\": 0,\"Rows\": [], \"InHospitalNum\": 0, \"PreHospitalNum\": 0, \"PathWayNum\": 0}";
            if (resultInfo.Result == 1)
            {
                var listData = JsonConvert.DeserializeObject<dynamic>(resultInfo.Body.ToString());
                var result = new { Total = listData.PatientNum.Value, Rows = listData.PatientList, InHospitalNum = listData.InHospitalNum.Value, PreHospitalNum = listData.PreHospitalNum.Value, PathWayNum = listData.PathWayNum.Value };
                return JsonDate(result);
            }
            else
            {
                NoData = "{\"Total\": 0,\"Rows\":[],\"Result\":\"" + resultInfo.Result + "\",\"Body\":\"" + resultInfo.Body + "\",\"InHospitalNum\": 0, \"PreHospitalNum\": 0, \"PathWayNum\": 0}";
            }
            return Content(NoData);
        }
    }
}
